﻿using System.Configuration;

namespace RuTrackerLib.Editors.Links.Editors
{
    class GenericLinkEditor : ILinkEditor
    {
        private readonly string _rootPath;

        public GenericLinkEditor(string rootPath)
        {
            _rootPath = rootPath;
        }

        public Link EditLink(Link link)
        {
            string siteRootPath = ConfigurationManager.AppSettings["SiteRootPath"];

            Link newLink = link.Clone();
            string encryptedHref = QueryStringEncryptor.Encrypt(string.Format("{0}/{1}", _rootPath, link.HRef));
            newLink.HRef = string.Format("{0}{1}?query={2}", siteRootPath, Const.RedirectUrl, encryptedHref);
            return newLink;
        }
    }
}
